﻿using BingVis.GoogleTransit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BingVis.Common;
using System.Threading;

namespace BingVis.GoogleTransit.Test
{
    
    
    /// <summary>
    ///This is a test class for SelectiveFareTapLoaderTest and is intended
    ///to contain all SelectiveFareTapLoaderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SelectiveFareTapLoaderTest : FareTapLoaderTest
    {
        /// <summary>
        ///A test for ProcessItem
        ///</summary>
        [TestMethod()]
        public void Should_Process_10_Items_From_TestContents_With_NewtonCentre_Filter()
        {
            IGTFSFile file = new GTFSFile("blah.txt", testFareContents);
            SelectiveFareTapLoader loader = new SelectiveFareTapLoader(file, "Newton Centre");
            int processedCount = 0;
            bool done = false;
            loader.ItemLoaded += (x, y) => processedCount++;
            loader.DoneProcessing += (x, y) => done = true;

            loader.ProcessFile();
            while (!done)
            { Thread.Sleep(200); }

            Assert.AreEqual<int>(10, loader.Items.Count);
        }

        /// <summary>
        ///A test for ProcessItem
        ///</summary>
        [TestMethod()]
        public void Should_Process_0_Items_From_TestContents_With_BadStop_Filter()
        {
            IGTFSFile file = new GTFSFile("blah.txt", testFareContents);
            SelectiveFareTapLoader loader = new SelectiveFareTapLoader(file, "Bad Stop");
            int processedCount = 0;
            bool done = false;
            loader.ItemLoaded += (x, y) => processedCount++;
            loader.DoneProcessing += (x, y) => done = true;

            loader.ProcessFile();
            while (!done)
            { Thread.Sleep(200); }

            Assert.AreNotEqual<int>(10, loader.Items.Count);
            Assert.AreEqual<int>(0, loader.Items.Count);
        }
    }
}
